<template>
  <div>
    <ul>
      <li v-for="(message,index) in messages" :key="message.id">
        <!--        <a href="??">{{ message.title }}</a>-->
        <!--        <router-link to="/home/message/detail/"></router-link>-->
        <!--        这里采用params方式传递参数-->
        <!--        <router-link :to="`/home/message/detail/${message.id}`">{{ message.title }}</router-link>-->
        <!--        下面采用query方式传递参数-->
        <router-link :to="`/home/message/detail/?id=${message.id}`">{{ message.title }}</router-link>
        <button @click="pushShow(message.id)">push查看</button>
        <button @click="replaceShow(message.id)">replace查看</button>
      </li>
    </ul>
    <button @click="$router.back()">返回</button>
    <hr>
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  name: 'message',
  data() {
    return {
      messages: []
    }
  },
  mounted() {
    // 模拟从后台获取数据
    setTimeout(() => {
      const messages = [
        {
          id: 1,
          title: 'message001'
        }, {
          id: 2,
          title: 'message002'
        }, {
          id: 3,
          title: 'message003'
        }
      ]
      this.messages = messages
    }, 200)
  },
  methods: {
    // 编程式路由导航 ：通过调用方法改变路由器中 栈结构里面的路由
    pushShow(id) {
      this.$router.push(`/home/message/detail/${id}`)
    },
    replaceShow(id) {
      this.$router.replace(`/home/message/detail/${id}`)
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
